<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="../static/css/prism.css" rel="stylesheet" />
</head>

<body>
    <strong style="color:blueviolet">本节无script演示</strong>

    <h2>join() 将数组内元素合并为字符串</h2>
    <p>以给的参数为分隔，将数组内元素合并为字符串，若不提供参数，默认以逗号分隔（对照字符串方法 split()）</p>
    <pre><code class="language-javascript">var a = [1, 2, 3, 4];

a.join(' ') // '1 2 3 4'
a.join(' | ') // "1 | 2 | 3 | 4"
a.join() // "1,2,3,4"
['a',, 'b'].join('-')  // 'a--b'</code></pre>
    <p>若合并的元素为 undefined 或 null，会被视为空字符串</p>
    <pre><code class="language-javascript">[undefined, null].join('#')  // '#'</code></pre>
    
    <script src="../static/js/prism.min.js"></script>
</body>

</html>